﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UIFollow : MonoBehaviour
{
    public GameObject target;

    public float xOffset = 0f;
    public float yOffset = 40f;
    RectTransform rectTransform;
    // Start is called before the first frame update
    void Start()
    {

        rectTransform = GetComponent<RectTransform>();
    }

    // Update is called once per frame
    void Update()
    {
        Vector2 player2DPosition = Camera.main.WorldToScreenPoint(target.transform.position);
        if (player2DPosition.x == Mathf.Infinity || player2DPosition.y == Mathf.Infinity){
            gameObject.SetActive(false);
        }else{
            gameObject.SetActive(true);
            rectTransform.position = player2DPosition + new Vector2(xOffset, yOffset);
        }
    }
}
